//////////////////////////////////////////////////////////////////////////
//
// GAM203
// Bird actor
// Bird.h
// 
// Grant Johnson
// Qantm College
//
//////////////////////////////////////////////////////////////////////////

#include "Bird.h"

#include "DXMgr.h"
#include "InputMgr.h"
#include "World.h"
#include "Renderer.h"

Bird::Bird()
{
	//Create the dwarf mesh
	m_mesh.CreateObject(DXMgr::GetInstance().GetDevice(), "media/Meshes/tiger.x");

	//Calculate the bounding box
	DWORD* pVertices = NULL;
	m_mesh.GetMesh()->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
	D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices, m_mesh.GetMesh()->GetNumVertices(), D3DXGetFVFVertexSize(m_mesh.GetMesh()->GetFVF()), &m_minBounds, &m_maxBounds);
	m_mesh.GetMesh()->UnlockVertexBuffer();

	//Set the loading position
	m_pos = D3DXVECTOR3(15, 25, 9);
}

Bird::~Bird()
{
}

void Bird::Update(float a_dt)
{
	//Stick to the terrain height
	//m_pos.y = World::GetInstance().GetTerrainHeight(m_pos.x, m_pos.z) + 0.5f;

	// Set our Drawable's world matrix based on our position and rotation
	D3DXMATRIX transMat;
	D3DXMATRIX rotMat;

	D3DXMatrixTranslation(&transMat, m_pos.x, m_pos.y, m_pos.z);
	//@HACK: Add D3DX_PI to make up for Dwarf model facing -Z dir :(
	D3DXMatrixRotationYawPitchRoll(&rotMat, GetYaw(), GetPitch(), GetRoll());

	//Update the world matrix of the dwarf
	m_mesh.SetWorldMatrix(rotMat * transMat);
}
void Bird::UseAbility(const int a_index)
{
	switch(a_index)
	{
	case 0:
		{
		}
		break;
	default:
		break;
	}
}
D3DXVECTOR3 Bird::GetCameraAttachPos() const
{
	//HACK - This hardcoded value has to be used in this instance
	// for the dual cameras culling from one camera. This hardcoded 
	// value would be replaced with the commented out section to get
	// the values from the active camera

	D3DXVECTOR4 outputVec = D3DXVECTOR4(0.0f,3.0f,5.0f,0.0f);
	/*D3DXVECTOR3 cameraPos = Renderer::GetInstance().GetActiveCamera().GetOffset();
	outputVec.x = cameraPos.x;
	outputVec.y = cameraPos.y;
	outputVec.z = cameraPos.z;*/

	//Rotate by yaw pitch and roll
	D3DXMATRIX tempMat;
	D3DXMatrixRotationYawPitchRoll(&tempMat, GetYaw(), GetPitch(), GetRoll());
	D3DXVec4Transform(&outputVec, &outputVec, &tempMat);

	outputVec.x += m_pos.x;
	outputVec.y += m_pos.y;
	outputVec.z += m_pos.z;

	//convert from matrix to vector
	return (D3DXVECTOR3)outputVec;
}
D3DXVECTOR3 Bird::GetCameraTrackPos() const
{
	D3DXVECTOR3 trackPos = m_pos;
	//Stop camera looking at his feet
	trackPos.y += 1;
	return trackPos;
}